TextField

The text field class implements a single line text entry area. TextField is a sub class of textcomponent.
Constructors
TextField( )
TextField(int no.of chars)
TextField(string)
TextField(string,int no of chars)
Methods
string getText( )
void setText(string)
string getSelected text( )
void select(int start index,int index)
boolean isEditable( )
void setEditable(Bolean)
void setEchoChar(char)
boolean echoCharIsSet( )
char getEchoChar( )

 

WRITE A PROGRAM ON TEXTFIELD.

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Text extends Applet implements ActionListener
{
TextField n,p;
public void init()
{
Label na=new Label("Name: ",Label.RIGHT);
Label pa=new Label("PassWord: ",Label.RIGHT);
n=new TextField(12);
p=new TextField(8);
p.setEchoChar('*');
add(n);
add(p);
add(na);
add(pa);
n.addActionListener(this);
p.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
repaint();
}
public void paint(Graphics g)
{
g.drawString("Name: "+n.getText(),6,60);
g.drawString("Password: "+n.getText(),6,100);
}
}

/*<applet code=Text height=150 width=380>
</applet>*/

           

TextArea

Using text area we can include multiple lines of the text like an editor
Constructors
TextArea( )
TextArea(no of lines,no.of.char)
TextArea(string)
TextArea(string,no.oflines,no.ofchar)
TextArea(string.no.oflines,no.ofchars,scrollbar)
Methods
void append(string)
void insert(string,index)
void replaceRange(string,startindex,Endindex)

 

WRITE A PROGRAM ON TEXT AREA.

import java.awt.*;
import java.applet.*;
public class Area extends Applet
{
String s;
public void init()
{
s="         HELLO DEAR STUDENTS WELCOME TO VISION COMPUTERS.\n"+
"         THIS NOTES CAN BE PREPARED VISION COMPUTERS.";
TextArea text=new TextArea(s,10,60);
add(text);
}
}

/*<applet code=Area width=400 height=100>
</applet>*/